package com.sanploy.manage.service.impl;

import com.sanploy.common.domain.FreightModel;
import com.sanploy.common.domain.Test;
import com.sanploy.common.enums.Meta;
import com.sanploy.common.vo.BaseException;
import com.sanploy.manage.mapper.FreightMapper;
import com.sanploy.manage.service.FreightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhu yingzhi on 2017/9/14.
 * @author yingzhi zhu
 * 运费模板逻辑处理实现类
 */
@Service
public class FreightServiceImpl implements FreightService {

    @Autowired
    private FreightMapper freightMapper;
    @Override
    public int insertFreight(String name, boolean is_free, String province,String city,String county,String detail,
                             String position, String remote_json, String local_json) {

        return  freightMapper.insertFreight(name, is_free, province,city,county,detail, position, remote_json, local_json);
    }

    @Override
    public List<FreightModel> findAllFreight() {

        return freightMapper.findAll();
    }

//    @Override
//    public int deleteAllFreight(Long id) throws BaseException {
//        if (freightMapper.deleteFreight(id)!= 1){
//            throw  new BaseException(Meta.DeleteFail);
//        }
//            return 1;
//
//    }

    @Override
    public int updateFreight(Long id, String name, boolean is_free, String province, String city, String county, String detail, String position, String remote_json, String local_json) throws BaseException {
        if (freightMapper.updateFreight(id, name, is_free, province, city, county, detail, position, remote_json, local_json)!=1){
            throw new BaseException(Meta.UpdateFail);
        }
        return 1;
    }

    @Override
    public FreightModel findOne(Long id) {
        return freightMapper.selectFreightOne(id);
    }


    @Override
    public String test() {
        Test test = new Test();
        test.setName("asdads111");
        Map<String,Object> map = new HashMap<>();
        map.put("name","heheda123");
        map.put("id",12);
        freightMapper.test(map);

        return String.valueOf(map.get("id"));
    }
}
